#include "logger.h"
#include <iostream>

/// The one-and-only Logger instance.
Logger* Logger::instance_;

/// pimpl definition.
struct LoggerImpl {
	int level_;
	//Add a file handle to print all messages to log?
};

Logger::Logger() : pimpl_(new LoggerImpl())
{
	level(3); //Default to medium verbosity.
}

Logger::~Logger()
{
    delete instance_;
}

/// Gain access to the one-and-only Logger instance.
/// \return The one-and-only Logger instance.
Logger* Logger::instance()
{
    if( instance_ == 0 )
        instance_ = new Logger();
    return instance_;
}

/// Report an error.
/// \param message The error message to report.
/// \param logging_level The verbosity level of the message.  Used to
/// determine whether this message should be logged given a requested verbosity
/// level.
void Logger::error(const std::string& message, const int& logging_level) const
{
	if( logging_level <= level() )
		std::cerr << "ERROR:  " << message << '\n';
}

/// Report a warning.
/// \param message The warning message to report.
/// \param logging_level The verbosity level of the message.  Used to
/// determine whether this message should be logged given a requested verbosity
/// level.
void Logger::warning(const std::string& message, const int& logging_level) const
{
	if( logging_level <= level() )
		std::clog << "WARNING:  " << message << '\n';
}

/// Report an informative message.
/// \param message The message to report.
/// \param logging_level The verbosity level of the message.  Used to
/// determine whether this message should be logged given a requested verbosity
/// level.
void Logger::message(const std::string& message, const int& logging_level) const
{
	if( logging_level <= level() )
		std::cout << "INFO:  " << message << '\n';
}

/// Access the set verbosity level.
/// return The set verbosity level.
int Logger::level() const
{
	return pimpl_->level_;
}

/// Set the verbosity level.
/// \param The new verbosity level to set.
void Logger::level(const int& logging_level)
{
	pimpl_->level_ = logging_level;
}
